<script setup lang="ts">

import { screenListAPI } from '@/api/task'
import { taskStore } from '@/store/task'
import { Toast } from 'vant';
import { inject, reactive } from 'vue'

    const store = taskStore()
    const state = reactive({
        mode: '', 
        circle: ''
    })
    const getScreenList = async() => {
        const res = await screenListAPI()      
        if (res) {
            store.setScreenList(res.data)
        }else{
            Toast(res.message)
        }   
    }
    //serviceMode是否存在 执行获取城市列表
    if(!store.screenList.serviceMode) getScreenList()

    // 接收父级传递的关闭弹窗的方法
    const closeScreen = inject('closeScreen')
    // 点击返回 关闭弹窗
    const onClickLeft = () => closeScreen()
    
    // 清除
    const clearScreen = () => {
        state.mode = ''
        state.circle = ''
    }

</script>


<template>
    <van-nav-bar
        title="筛选"
        left-arrow
        @click-left="onClickLeft"
    >
        <template #left>
            <van-icon name="cross" size="18" />
        </template>
    </van-nav-bar>
    <div class="task-screen" >
        <h3>服务方式</h3>
        <div class="screen-item">
            <span 
                v-for="(item, index) in store.screenList.serviceMode" 
                :key="index" 
                :class="item == state.mode ?'active': ''"
                @click="state.mode = item"
            >
            {{ item }}
            </span>
        </div>
        <h3>任务周期</h3>
        <div class="screen-item">
            <span 
                v-for="(item, index) in store.screenList.taskCycle" 
                :key="index" 
                :class="item == state.circle ?'active': ''"
                @click="state.circle = item"
            >
            {{ item }}
            </span>
        </div>
    </div>
    <div class="screen-footer">
        <button class="screen-clear" @click="clearScreen">清除</button>
        <van-button type="primary" block @click="closeScreen(state)">确认</van-button>
    </div>
</template>

<style scoped>
.task-screen {
    padding: 0 0.6rem;
}
.task-screen h3 {
    font-size: 0.96rem;
    line-height: 0.96rem;
    font-weight: 500;
    color: #333333;
    margin: 0.8rem 0;
}
.task-screen span {
    width: 5.76rem;
    height: 1.6rem;
    line-height: 1.6rem;
    color: #666666;
    border-radius: 0.16rem;
    background: #F5F6F8;
    font-weight: 400;
    font-size: 0.75rem;
    text-align: center;
    display: inline-block;
    margin: 0 0.59rem 0.51rem 0;
}
.task-screen span:nth-child(3n) {
    margin-right: 0;
}
.task-screen span.active {
    color: #FF8A00;
    border: 1px solid #FE8F27;
}
.screen-footer {
    position: fixed;
    bottom: 0;
    background: #FFFFFF;
    box-shadow: 0rem 0rem 1rem 0rem rgba(208,208,208,0.39);
    display: flex;
    padding: 0.83rem 0.64rem;
    width: calc(100vw - 1.28rem);
}
.screen-clear {
    width: 5.33rem;
    height: 2.35rem;
    background: #F5F6F8;
    border-radius: 0.27rem;
    font-weight: bold;
    font-size: 0.8rem;
    color: #666565;
    border: 0;
    margin-right: 0.64rem;
}
</style>